﻿
Partial Public MustInherit Class command_autoJob(Of hash_t, impl_t As command_autoJob(Of hash_t, impl_t))
    Inherits autoJob(Of hash_t, impl_t)

    Public command As Byte = job.command.invalid

    Protected NotOverridable Overrides Function required(ByVal i As Int64) As Boolean
        assert(i >= 0 AndAlso i < field.field_required_commands.Length())
        If i = field.command_field_id Then
            Return True
        Else
            Return field.field_required_commands(i).valid() AndAlso (+field.field_required_commands(i)).has(command)
        End If
    End Function

    Protected NotOverridable Overrides Function respond(ByVal i As Int64) As Boolean
        assert(i >= 0 AndAlso i < field.field_respond_commands.Length())
        If i = field.command_field_id Then
            Return True
        Else
            Return Not field.field_respond_commands(i).valid() OrElse (+field.field_respond_commands(i)).has(command)
        End If
    End Function

    Protected Overridable Function command_valid() As Boolean
        Return True
    End Function

    Private Shared Function command_valid(ByVal i As impl_t, ByVal field_id As Int64) As Boolean
        assert(Not i Is Nothing)
        Return i.command_valid()
    End Function
End Class
